{% extends 'warehouse/base.html' %}

{% block title %}商品详情{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-12">
        <h1>商品详情</h1>
        
        {% if messages %}
            {% for message in messages %}
                <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                    {{ message }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            {% endfor %}
        {% endif %}
        
        <div class="card">
            <div class="card-header">
                <h3>{{ goods.name }}</h3>
            </div>
            <div class="card-body">
                <table class="table table-bordered">
                    <tr>
                        <th>商品名称</th>
                        <td>{{ goods.name }}</td>
                    </tr>
                    <tr>
                        <th>规格</th>
                        <td>{{ goods.specification|default:"-" }}</td>
                    </tr>
                    <tr>
                        <th>单位</th>
                        <td>{{ goods.unit }}</td>
                    </tr>
                    <tr>
                        <th>保质期</th>
                        <td>
                            {% if goods.shelf_life %}
                                {{ goods.shelf_life }}天
                            {% else %}
                                无保质期
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th>最小库存</th>
                        <td>{{ goods.min_stock }}</td>
                    </tr>
                    <tr>
                        <th>最大库存</th>
                        <td>{{ goods.max_stock }}</td>
                    </tr>
                    <tr>
                        <th>创建人</th>
                        <td>{{ goods.creator.username }}</td>
                    </tr>
                </table>
            </div>
        </div>
        
        <div class="card mt-4">
            <div class="card-header">
                <h3>库存信息</h3>
            </div>
            <div class="card-body">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>货位编号</th>
                            <th>批次号</th>
                            <th>数量</th>
                            <th>过期日期</th>
                            <th>更新时间</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for stock in stocks %}
                        <tr>
                            <td>{{ stock.location }}</td>
                            <td>{{ stock.batch_number }}</td>
                            <td>{{ stock.quantity }}</td>
                            <td>{{ stock.expiration_date|default:"-" }}</td>
                            <td>{{ stock.updated_at|date:"Y-m-d H:i" }}</td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="5">暂无库存信息</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
        
        <div class="mt-3">
            {% if 'goods_update' in user_permissions %}
            <a href="{% url 'warehouse:goods_edit' goods.id %}" class="btn btn-warning">编辑商品</a>
            {% endif %}
            <a href="{% url 'warehouse:goods_list' %}" class="btn btn-secondary">返回列表</a>
        </div>
    </div>
</div>
{% endblock %}